package com.hdstcloud.device.service.bo;

import com.frame.base.comm.persistence.BoBaseData;
import com.frame.base.comm.persistence.ConditionMatchMode;
import com.frame.base.comm.persistence.annotaion.PersisCondition;
import com.frame.base.comm.persistence.annotaion.PersisMethod;
import com.frame.base.comm.persistence.annotaion.SoleHolder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Dominic
 * @since 2020-11-02
 */

@PersisMethod(name = "getByDevId", condtions = {
        @PersisCondition(obj = "modelList.infoList", name = "id", valType = String.class, mode = ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "getDevInfoAndAttr", condtions = {
        @PersisCondition(obj = "modelList.infoList", name = "id", valType = String.class, mode = ConditionMatchMode.EQUALS),
        @PersisCondition(obj = "modelList.attr", name = "common", valType = Integer.class, mode =
                ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "getDevInfoByAttr", condtions = {
        @PersisCondition(obj = "modelList.infoList.attr.dataItemInfo", name = "id", valType = Integer.class,
                mode = ConditionMatchMode.EQUALS),
        @PersisCondition(obj = "modelList.infoList.attr", name = "rtValue", valType = String.class,
                mode = ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "fuzzyQueryByModelName", condtions = {
        @PersisCondition(obj = "modelList", name = "name", valType = String.class,
                mode = ConditionMatchMode.LIKE)
})

@PersisMethod(name = "listByDevIds", condtions = {
        @PersisCondition(obj = "modelList.infoList", name = "id", valType = List.class, mode = ConditionMatchMode.IN)
})

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class BoClass extends BoBaseData {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "JDBC")
    private Integer id;
    private String name;

    //该注解代表父对象是子对象唯一持有者，类似于一对一或者一对多的关系
    @SoleHolder
    private List<BoModel> modelList;

    public BoClass(String name) {
        this.name = name;
    }
}
